package com.um.jdy.platform.platform.manager;

import cn.hutool.core.bean.BeanUtil;
import com.um.jdy.common.base.enums.YesOrNo;
import com.um.jdy.common.platform.entity.dto.SharingSettingDTO;
import com.um.jdy.common.platform.entity.po.SharingSetting;
import com.um.jdy.common.platform.service.SharingSettingService;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import org.springframework.stereotype.Component;

/**
 * 管理类：分账设置
 */
@Component
public class SharingSettingManager extends BaseManager<SharingSettingService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<SharingSetting> get() {
        SharingSetting sharingSetting = service.getEntity("com_id", getComId());
        if(sharingSetting == null){
            sharingSetting = new SharingSetting();
            sharingSetting.setComId(getComId());
            sharingSetting.setSharingRate(0);
            sharingSetting.setProfitSharing(YesOrNo.No.name());
            service.save(sharingSetting);
        }
        return Response.success(sharingSetting);
    }

    /**
     * 更新
     *
     * @param id
     * @param appSettingDTO
     * @return
     */
    public Response update(String id, SharingSettingDTO appSettingDTO) {
        SharingSetting sharingSetting = BeanUtil.copyProperties(appSettingDTO, SharingSetting.class);
        sharingSetting.setPlatformSharingSettingId(id);
        service.updateEntity(sharingSetting);
        return Response.success();
    }
    
}
